package com.his.registration.controller;

import com.his.common.Result;
import com.his.registration.service.UserService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.controller
 * @Author: ZhangYing
 * @Date: 2023/7/7 14:09
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    //查询用户
    @RequestMapping("/verify")
    public Result verify(String username, String password){
        int result = userService.verify(username, password);
        if(result==1){
            return Result.success("用户验证成功");
        }
        else {
            return Result.error("用户验证失败");
        }
    }

    //注册
    @RequestMapping("/insert")
    public Result insert(String username,String password){
        //先保证用户名唯一
        int i = userService.selectByUsername(username);
        if(i!=0){
            return Result.error("该用户名已被注册");
        }
        else{
            int result = userService.insert(username, password);
            return Result.success("成功注册"+result+"名用户信息");
        }
    }

    //修改密码
    @RequestMapping("/update")
    public Result update(String username,String password){
        int result = userService.update(username, password);
        return Result.success("密码修改成功");
    }
}
